package com.Questions.hash;

import java.util.*;
/**
 * 猜数字游戏
 */
public class leetcode299 {
    public String getHint(String secret, String guess) {
        // 先计算位置和数字都正确的数量
        Map<Character,Integer> map1=new HashMap<>();
        Map<Character,Integer> map2=new HashMap<>();
        int aNum=0;
        int bNum=0;
        for(int i=0;i<secret.length();++i){
            Character c1=secret.charAt(i);
            Character c2=guess.charAt(i);
            if(c1==c2){
                aNum++;
            }else{
                map1.put(c1,map1.getOrDefault(c1,0)+1);
                map2.put(c2,map2.getOrDefault(c2,0)+1);
            }
        }
        for(Character key:map1.keySet()){
            if(map2.containsKey(key)){
                bNum+=Math.min(map1.get(key),map2.get(key));
            }
        }
        return new String(aNum+"A"+bNum+"B");
    }
}
